package com.aodesoft.power;

import java.lang.reflect.Method;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class AdminLoginInterceptor extends MethodFilterInterceptor {
	private static final long serialVersionUID = 1L;
	/**
	 * 后台登陆拦截
	 * @author tang
	 * @date 2011-10-10
	 * @param invocation
	 * @return
	 * @throws Exception
	 */
	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		Class<?> clzz=invocation.getAction().getClass();
		String methodName=invocation.getProxy().getMethod();
		System.out.print("后台拦截:"+clzz.getSimpleName()+"的"+methodName+"()方法");
		Method m= clzz.getMethod(methodName);
		
		AdmItp admItp = null;
		try {admItp=m.getAnnotation(AdmItp.class);} catch (Exception e) {}
		
		if(admItp!=null && admItp.value()==Itp.IN){
			System.out.println("  结果：拦截");
			return invocation.invoke();
		}else{
			System.out.println("  结果：放行");
			return invocation.invoke();
		}
		
		/*
		// 取得请求相关的ActionContext实例
		ActionContext ctx = invocation.getInvocationContext();
		Map session = ctx.getSession();
		if (session.get("login") != null ) {
			return invocation.invoke();
		}
		return "adminLogin";
		 */
	}
} 
